package pers.cz.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * 工具类，打印耗时
 * @program: PostGirl-panent
 * @description: TimeLag
 * @author: Cheng Zhi
 * @create: 2021-04-29 11:18
 **/
public class TimeLag {

    Logger logger = LoggerFactory.getLogger(TimeLag.class);

    private Date startDate;
    private Date endDate;

    TimeLag() {
        startDate = new Date();
    }

    /**
     * 返回耗时
     * @return
     */
    public String cost() {
        endDate = new Date();
        long cont = endDate.getTime() - startDate.getTime();
        String s = new StringBuffer().append("cost ").append(cont).append(" milliseconds (").append(cont / 1000).append(" seconds).").toString();
        return s;
    }

    public static void main(String[] args) {
        TimeLag lag = new TimeLag();
        int s = 0;
        for ( int i=0; i<100000; i++) {

            for (int j = 100000; j>i; j--) {
                s = j+i;
            }

        }
        System.out.println(s);
        System.out.println(lag.cost());
    }
}
